/*
* IO_Process.c
 *
 *  Created on: Oct 26, 2021
 *      Author: ZCM
 */
#include"IO_Process.h"
#include "SSC/Src/XMC_ESC.h"//头文件的引用需要注明相对路径
#include "UserApp/esc_uart.h"

extern GRIPPER_OBJECT *GRIP_OB_LIST[4];

//当串口能正常收发数据时，对应的串口灯亮，否则灯灭
uint8_t Manage_Uart_Status_LEDs(void)
{
	uint16_t write_LEDs = 0U;

	for(uint8_t grip_ob_index = 0; grip_ob_index< 4; grip_ob_index++)
	{
		if(GRIP_OB_LIST[grip_ob_index]->grip_id == 0)
		{
			continue;
		}

		//将4个端口的grip_state成员组合成控制字write_LEDs
		write_LEDs |= (uint16_t)(GRIP_OB_LIST[grip_ob_index]->grip_state << grip_ob_index);
	}
	BUS_IO_Write(&Port_State_LEDs, (~write_LEDs));//将第i个端口的grip_state成员写入第i个端口的LED驱动管脚

	return 0;
}

uint8_t Read_IO_Bus(void)
{
	uint16_t io_states = 0U;

	io_states = BUS_IO_Read(&Px_TMS_Inputs);//读取输入管脚的状态
	for(uint8_t grip_ob_index = 0; grip_ob_index< 4; grip_ob_index++)
	{
		if(GRIP_OB_LIST[grip_ob_index]->grip_id == 0)
		{
			continue;
		}

		//将第i个夹爪的输入(以盒子为参考)管脚状态写入第i个PDO的GripState成员
		GRIP_OB_LIST[grip_ob_index]->feedback_object->GripperState = (uint16_t)((io_states>>(grip_ob_index*2)) & (uint16_t)0x03);
	}

	return 0;
}




